<?php 
session_start();
/*
 *  This file shows the person's profile and also allows to edit person's profile. 
 *  The peron's profile can be Student or faculty.
 *  INPUT:
 *       Person's SSN.
 *  NOTE: checking of loggedin condition etc.       
 * */

if (!isset($personSSN)) {
	echo "<h3> Error: person ssn not set </h3>";
	return;
}
$isAdmin = false;  // true - admin; false -  user
$isStudent = true;  // true - student; false - faculty


// DB connect  
require "config.php";
$con = mysql_connect("localhost",$db_user ,$db_pass);
if (!$con){
	die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);


// Get the person details from db
$sql_read = "select * from person where (SSN = '$personSSN')";
$result = mysql_query($sql_read);
while($row = mysql_fetch_array($result)) {
	$firstName = $row["firstName"];
	$lastName = $row["lastName"]; 
	$email = $row["email"];
	$gender = $row["gender"]; 
	$Bdate = $row["birthDate"];
	$apt = $row["apartmentNumber"];
	$st = $row["streetNumber"];
	$city = $row["city"];
	$state = $row["state"];
	$zip = $row["zipcode"];
	break;
}

$q2 = "select * from student where (SSN = '$personSSN')";
$r2 = mysql_query($q2);
while($row = mysql_fetch_array($r2)) {
	$isStudent = true;
	$gpa = $row["GPA"]; 
	$major = $row["major"];
	$term = $row["term"];
	$fees = $row["fees"];
	break;
}

$q3 = "select * from faculty where (SSN = '$personSSN')";
$r3 = mysql_query($q3);
while($row = mysql_fetch_array($r3)) {
	$isStudent = false;
	$designation = $row["designation"];
	$salary = $row["salary"];
	break;
}
mysql_close($con);
?>


<!--  html code -->
<h3  style="color:red">
<?php 
if(isset($_SESSION["shwetha_result"])) {
	echo $_SESSION["shwetha_result"];
	unset($_SESSION["shwetha_result"]);
}
?>
</h3>
<form action="PersonProfileProcess.php" method="POST">
<input type="hidden" name="ssn_name" value="<?php echo $personSSN?>" \>
<table>
	<tr><td> SSN </td>: <td> <label><?php echo $personSSN?></label> </td></tr>
	<tr><td> First Name: </td> <td> <input type="text" name="FName" value="<?php echo $firstName?>" />  </td></tr>
	<tr><td> Last Name: </td> <td> <input type="text" name="LName" value="<?php echo $lastName?>" />  </td></tr>
	<tr><td> Email: </td> <td> <input type="text" name="Email" value="<?php echo $email?>" />  </td></tr>
	<tr><td> Gender: </td> <td> <label> <?php echo $gender?></label></td></tr>
	<tr><td> Birth Date: </td> <td> <label> <?php echo $Bdate?></label></td></tr>
</table>
<hr/>
<table>
	<th align="left"> Address: </th>
    <tr><td> Street Name: </td><td> <input type="text" name="StName" value="<?php echo $st?>" />  </td></tr>
    <tr><td> Apartment Number: </td><td> <input type="text" name="AptNo" value="<?php echo $apt?>" />  </td></tr>
    <tr><td> City </td><td> <input type="text" name="cityNo" value="<?php echo $city?>" />  </td></tr>
    <tr><td> State </td><td> <input type="text" name="state" value="<?php echo $state?>" />  </td></tr>
    <tr><td> Zip </td> <td> <input type="text" name="zip" value="<?php echo $zip?>" />  </td></tr>
</table>
<hr/>
<?php 
if($isStudent) {
?>
<table>
<tr>
	<td>GPA:</td>
	<?php if($isAdmin) { ?>
		<td><input type="text" name="gpa" value="<?php echo $gpa?>" /> </td>
	<?php } else {?>
		 <td> <label> <?php echo $gpa?></label></td>
	<?php }?>
</tr>
<tr><td> Major: </td> <td> <input type="text" name="major" value="<?php echo $major?>" />  </td></tr>
<tr><td> Term: </td> <td> <input type="text" name="term" value="<?php echo $term?>" />  </td></tr>
<tr>
	<td>Fees:</td>
	<?php if($isAdmin) { ?>
		<td><input type="text" name="fees" value="<?php echo $fees?>" /> </td>
	<?php } else {?>
		 <td> <label> <?php echo $fees?></label></td>
	<?php }?>
</tr>
</table>


<?php 
} else {
?>
<table>
<tr><td> Designation: </td> <td> <input type="text" name="designation" value="<?php echo $designation?>" />  </td></tr>
<tr>
	<td>Salary:</td>
	<?php if($isAdmin) { ?>
		<td><input type="text" name="salary" value="<?php echo $salary?>" /> </td>
	<?php } else {?>
		 <td> <label> <?php echo $salary?></label></td>
	<?php }?>
</tr>

</tr>
</table>
<?php 
}
?>


<input type="submit" value="Save" id="submit" />
</form>
